package net.xdclass.service.impl;

import net.xdclass.controller.request.LinkGroupAddRequest;
import net.xdclass.controller.request.LinkGroupUpdateRequest;
import net.xdclass.interceptor.LoginInterceptor;
import net.xdclass.manager.LinkGroupManager;
import net.xdclass.model.LinkGroupDO;
import net.xdclass.service.LinkGroupService;
import net.xdclass.vo.LinkGroupVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 王展
 * @since 2024-07-21
 */
@Service
public class LinkGroupServiceImpl implements LinkGroupService {
    @Autowired
    private LinkGroupManager linkGroupManager;
    @Override
    public int add(LinkGroupAddRequest linkGroupAddRequest) {
        long accountNo = LoginInterceptor.threadLocal.get().getAccountNo();
        LinkGroupDO linkGroupDO = new LinkGroupDO();
        linkGroupDO.setAccountNo(accountNo);
        linkGroupDO.setTitle(linkGroupAddRequest.getTitle());
        int rows = linkGroupManager.add(linkGroupDO);
        return rows;
    }

    @Override
    public boolean del(String groupId) {
        long accountNo = LoginInterceptor.threadLocal.get().getAccountNo();
        boolean isDel = linkGroupManager.del(groupId,accountNo);
        return isDel;
    }

    @Override
    public LinkGroupVO detail(Long groupId) {
        long accountNo = LoginInterceptor.threadLocal.get().getAccountNo();
        LinkGroupDO linkGroupDO = linkGroupManager.detail(groupId,accountNo);
        LinkGroupVO linkGroupVO = new LinkGroupVO();
        BeanUtils.copyProperties(linkGroupDO,linkGroupVO);
        return linkGroupVO;
    }

    @Override
    public List<LinkGroupVO> listAll() {
        long accountNo = LoginInterceptor.threadLocal.get().getAccountNo();
        List<LinkGroupVO> linkGroupVO = linkGroupManager.listAll(accountNo);
        return linkGroupVO;
    }

    @Override
    public int update(LinkGroupUpdateRequest request) {
        long accountNo = LoginInterceptor.threadLocal.get().getAccountNo();
        int rows = linkGroupManager.update(request,accountNo);
        return rows;
    }
}
